﻿<!DOCTYPE html>
<html>
  <head>
    <script src="./node_modules/docx/build/index.umd.js"></script>
    <script src="./FileSaver.js"></script>
    <!-- <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>  -->
    <style>
      .upload-div{
        margin-bottom: 20px;
      }
      #uploadButton {  
          padding: 10px 20px;  
          font-size: 16px;  
          cursor: pointer;  
      }  
        
      .popup {  
          display: none;
          position: fixed;  
          z-index: 1;  
          left: 0;  
          top: 0;  
          width: 100%;  
          height: 100%;  
          overflow: auto;  
          background-color: rgb(0,0,0);  
          background-color: rgba(0,0,0,0.4);   
      }  
        
      .popup-content {  
          background-color: #fefefe;  
          margin: 15% auto; 
          padding: 20px;  
          border: 1px solid #888;  
          width: 80%;  
          max-width: 600px;  
          text-align: center;  
          box-shadow: 0 5px 15px rgba(0,0,0,0.3);  
          border-radius: 5px;  
      }  
        
      .close-button {  
          color: #aaa;  
          float: right;  
          font-size: 28px;  
          font-weight: bold;  
          cursor: pointer;  
      }  
        
      .close-button:hover,  
      .close-button:focus {  
          color: black;  
          text-decoration: none;  
          cursor: pointer;  
      }
    </style>
  </head>

  <body>
    <h1>报告自动生成系统</h1>  
    <div class="upload-div">
      <div>
        <button id="uploadButton1">耕地保护监管文件上传</button>  
        <input type="file" id="fileInput1"> 
      </div>
      <div style="margin-top: 10px;">
        <button><a href="word1.html" target="_blank">耕地保护监管报告下载</a></button>
      </div>
    </div>
    <div class="upload-div">
      <div>       
        <button id="uploadButton2">林地资源监管文件上传</button>  
        <input type="file" id="fileInput2">
      </div>
      <div style="margin-top: 10px;">
        <button><a href="word2.html" target="_blank">林地保护监管报告下载</a></button>
      </div>
    </div>
    <div class="upload-div">
      <div>
        <button id="uploadButton31">持证矿山</button>  
        <input type="file" id="fileInput31">
        <button id="uploadButton32">废弃矿山</button>  
        <input type="file" id="fileInput32">
      </div>
      <div style="margin-top: 10px;">
        <button><a href="word3.html" target="_blank">矿山遥感监测报告下载</a></button>
      </div>      
    </div>
    <div class="upload-div">
      <div>
        <button id="uploadButton4">自然保护地监测文件上传</button>  
        <input type="file" id="fileInput4">
      </div>
      <div style="margin-top: 10px;">
        <button><a href="word4.html" target="_blank">自然保护地监测报告下载</a></button>
      </div>
    </div>
    <div class="upload-div">
      <div>
        <button id="uploadButton51">未供即用监测文件上传</button>  
        <input type="file" id="fileInput51">  
        <button id="uploadButton52">未供即用年末库文档文件上传</button>  
        <input type="file" id="fileInput52">    
      </div>
      <div style="margin-top: 10px;">
        <button><a href="word5.html" target="_blank">未供即用监测报告下载</a></button>
      </div>
    </div>  
    <div id="popup" class="popup">  
      <div class="popup-content">  
          <span class="close-button" id="confirmButton">&times;</span>  
          <p id="popupcontent"></p>  
      </div>  
    </div> 
    
  </body>  
  </html>

  <script>
    document.getElementById('uploadButton1').addEventListener('click', async function() {  
      var fileInput1 = document.getElementById('fileInput1');  
      var file1 = fileInput1.files[0]; 
    
      if (!file1) {  
          alert('Please select a file first!');  
          return;  
      }        
      var formData1 = new FormData();  
      formData1.append('file', file1);       
      try {  
          var response = await fetch('http://192.168.3.35:8091/exceltoword/insertgdexcelfile', {  
              method: 'POST',  
              body: formData1,  
          });  
          if (!response.ok) {  
              throw new Error('Network response was not ok');  
          } 
          var result = await response.json(); 
          var resultValue = result.result;

          var popup = document.getElementById('popup');  
          var popupcontent = document.getElementById('popupcontent');
          popup.style.display = 'block';  
          popupcontent.innerHTML = resultValue;
          console.log('File uploaded successfully:', result);  
      } catch (error) {  
          console.error('Error uploading file:', error);  
      }  
    });
    document.getElementById('uploadButton2').addEventListener('click', async function() {  
        var fileInput2 = document.getElementById('fileInput2');  
        var file2 = fileInput2.files[0]; 
      
        if (!file2) {  
            alert('Please select a file first!');  
            return;  
        }        
        var formData2 = new FormData();  
        formData2.append('file', file2);       
        try {  
            var response = await fetch('http://192.168.1.105:8091/exceltoword/insertldexcelfile', {  
                method: 'POST',  
                body: formData2,  
            });  
            if (!response.ok) {  
                throw new Error('Network response was not ok');  
            } 
            var result = await response.json(); 
            var resultValue = result.result;

            var popup = document.getElementById('popup');  
            var popupcontent = document.getElementById('popupcontent');
            popup.style.display = 'block';  
            popupcontent.innerHTML = resultValue;
            console.log('File uploaded successfully:', result);  
        } catch (error) {  
            console.error('Error uploading file:', error);  
        }  
    });
    document.getElementById('uploadButton31').addEventListener('click', async function() {  
        var fileInput31 = document.getElementById('fileInput31');  
        var file31 = fileInput31.files[0]; 
      
        if (!file31) {  
            alert('Please select a file first!');  
            return;  
        }        
        var formData31 = new FormData();  
        formData31.append('file', file31);       
        try {  
            var response = await fetch('http://192.168.1.105:8091/exceltoword/insertKsczexcelfile', {  
                method: 'POST',  
                body: formData31,  
            });  
            if (!response.ok) {  
                throw new Error('Network response was not ok');  
            } 
            var result = await response.json(); 
            var resultValue = result.result;

            var popup = document.getElementById('popup');  
            var popupcontent = document.getElementById('popupcontent');
            popup.style.display = 'block';  
            popupcontent.innerHTML = resultValue;
            console.log('File uploaded successfully:', result);  
        } catch (error) {  
            console.error('Error uploading file:', error);  
        }  
    });
    document.getElementById('uploadButton32').addEventListener('click', async function() {  
        var fileInput32 = document.getElementById('fileInput32');  
        var file32 = fileInput32.files[0]; 
      
        if (!file32) {  
            alert('Please select a file first!');  
            return;  
        }        
        var formData32 = new FormData();  
        formData32.append('file', file32);       
        try {  
            var response = await fetch('http://192.168.1.105:8091/exceltoword/insertKsfqexcelfile', {  
                method: 'POST',  
                body: formData32,  
            });  
            if (!response.ok) {  
                throw new Error('Network response was not ok');  
            } 
            var result = await response.json(); 
            var resultValue = result.result;

            var popup = document.getElementById('popup');  
            var popupcontent = document.getElementById('popupcontent');
            popup.style.display = 'block';  
            popupcontent.innerHTML = resultValue;
            console.log('File uploaded successfully:', result);  
        } catch (error) {  
            console.error('Error uploading file:', error);  
        }  
    });
    document.getElementById('uploadButton4').addEventListener('click', async function() {  
        var fileInput4 = document.getElementById('fileInput4');  
        var file4 = fileInput4.files[0]; 
      
        if (!file4) {  
            alert('Please select a file first!');  
            return;  
        }        
        var formData4 = new FormData();  
        formData4.append('file', file4);       
        try {  
            var response = await fetch('http://192.168.1.105:8091/exceltoword/insertZrbhdexcelfile', {  
                method: 'POST',  
                body: formData4,  
            });  
            if (!response.ok) {  
                throw new Error('Network response was not ok');  
            } 
            var result = await response.json(); 
            var resultValue = result.result;

            var popup = document.getElementById('popup');  
            var popupcontent = document.getElementById('popupcontent');
            popup.style.display = 'block';  
            popupcontent.innerHTML = resultValue;
            console.log('File uploaded successfully:', result);  
        } catch (error) {  
            console.error('Error uploading file:', error);  
        }  
    });
    document.getElementById('uploadButton51').addEventListener('click', async function() {  
        var fileInput51 = document.getElementById('fileInput51');  
        var file51 = fileInput51.files[0]; 
      
        if (!file51) {  
            alert('Please select a file first!');  
            return;  
        }        
        var formData51 = new FormData();  
        formData51.append('file', file51);       
        try {  
            var response = await fetch('http://192.168.1.105:8091/exceltoword/insertWgjyexcelfile', {  
            // var response = await fetch('http://192.168.1.105:8091/exceltoword/insertWgjyNMKexcelfile', {    
                method: 'POST',  
                body: formData51,  
            });  
            if (!response.ok) {  
                throw new Error('Network response was not ok');  
            } 
            var result = await response.json(); 
            var resultValue = result.result;

            var popup = document.getElementById('popup');  
            var popupcontent = document.getElementById('popupcontent');
            popup.style.display = 'block';  
            popupcontent.innerHTML = resultValue;
            console.log('File uploaded successfully:', result);  
        } catch (error) {  
            console.error('Error uploading file:', error);  
        }  
    });
    document.getElementById('uploadButton52').addEventListener('click', async function() {  
        var fileInput52 = document.getElementById('fileInput52');  
        var file52 = fileInput52.files[0]; 
      
        if (!file52) {  
            alert('Please select a file first!');  
            return;  
        }        
        var formData52 = new FormData();  
        formData52.append('file', file52);       
        try {  
            // var response = await fetch('http://192.168.1.105:8091/exceltoword/insertWgjyexcelfile', {  
            var response = await fetch('http://192.168.1.105:8091/exceltoword/insertWgjyNMKexcelfile', {    
                method: 'POST',  
                body: formData52,  
            });  
            if (!response.ok) {  
                throw new Error('Network response was not ok');  
            } 
            var result = await response.json(); 
            var resultValue = result.result;

            var popup = document.getElementById('popup');  
            var popupcontent = document.getElementById('popupcontent');
            popup.style.display = 'block';  
            popupcontent.innerHTML = resultValue;
            console.log('File uploaded successfully:', result);  
        } catch (error) {  
            console.error('Error uploading file:', error);  
        }  
    });
    document.getElementById('confirmButton').addEventListener('click', function() {  
        var popup = document.getElementById('popup');  
        popup.style.display = 'none';  
    });  
    
    window.onclick = function(event) {  
        var popup = document.getElementById('popup');  
        if (event.target == popup) {  
            popup.style.display = 'none';  
        }  
    }  
    
    document.querySelector('.close-button').onclick = function(event) {  
        event.stopPropagation();  
    };
  </script>
  </body>
</html>
